<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/21
 * Time: 15:33
 */

namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
        $this->display();
    }
    public function login(){
//        $name=I('username');
//        echo $name+"111";
//        exit();
        //首先进行验证码的检验
        $verify=new \Think\Verify();//创建生成验证类型的对象
        if ($verify->check(I('verify'))==false){
            $this->error("验证码错误!");
        }
        /*进行比较，检测用户信息，正确则进入后台首页*/
        $user=M('Admin');//系统自带模型
        $username=I('aname');
        $pwd=md5(I('apassword'));

        if ($user->where("`aname`='$username' AND `apassword`='$pwd'")->find()){
            //判断为真，表明登录成功
            session('username',$username);
            /*跳转到Index控制器*/
            redirect(U('/Home/Index/index/'),0,'跳转中...');
        }else{
//            echo $user->getLastSql();
//            exit();
            $this->error("用户名或密码错误!");
        }
    }
}